//
//  StatusTool.m
//  CMJWeibo
//
//  Created by BH on 15/12/16.
//
//

#import "StatusTool.h"
#import "HttpTool.h"
#import "MJExtension.h"

@implementation StatusTool

+(void)homeStatusWithParam:(HomeStatusParam *)param success:(void (^)(HomeStatusResult *))success failure:(void (^)(NSError *))failure
{
    [HttpTool getWithURL:@"https://api.weibo.com/2/statuses/home_timeline.json" params:param.keyValues success:^(id json) {
        
        if (success) {
            
            HomeStatusResult *result = [HomeStatusResult objectWithKeyValues:json];
            success(result);
            
            [result.keyValues writeToFile:@"/Users/apple/Desktop/home.plist" atomically:YES];
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

+(void)sendStatusWithParam:(SendStatusParam *)param success:(void (^)(SendStatusResult *))success failure:(void (^)(NSError *))failure
{
    [HttpTool postWithURL:@"https://api.weibo.com/2/statuses/update.json" params:param.keyValues success:^(id json) {
        if (success) {
            SendStatusResult *result = [SendStatusResult objectWithKeyValues:json];
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

+(void)getStatusCommentWithParam:(DetailStatusParam *)param success:(void (^)(DetailStatusResult *))success failure:(void (^)(NSError *))failure
{
    [HttpTool getWithURL:@"https://api.weibo.com/2/comments/show.json" params:param.keyValues success:^(id json) {
        if (success) {
            DetailStatusResult *result = [DetailStatusResult objectWithKeyValues:json];
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

@end
